package com.course.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class ListNumberFilter implements Filter
{
	FilterConfig config = null;

	public void destroy()
	{
		this.config = null;
	}

	public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException,
			ServletException
	{
		HttpServletRequest req = ( HttpServletRequest )request;
		Long listNumber = ( Long )req.getSession().getAttribute( "listNumber" );
		if(listNumber == null)
		{
			listNumber =  Long.parseLong( config.getInitParameter( "listNumber" ) ) ;
			req.getSession().setAttribute( "listNumber", listNumber );
		}
		chain.doFilter( request, response );
	}

	public void init( FilterConfig filterConfig ) throws ServletException
	{
		this.config = filterConfig;
	}

}
